import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../config/theme_color.dart';

class ConfirmAlertDialog {
  static showCommonDialog({required Widget childWidget}) {
    return Dialog(
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(16),
        ),
        elevation: 0,
        backgroundColor: Colors.transparent,
        child: Container(
          padding: const EdgeInsets.all(20),
          decoration: BoxDecoration(
            shape: BoxShape.rectangle,
            color: Colors.white,
            borderRadius: BorderRadius.circular(16),
          ),
          child: childWidget,
        ));
  }

  static showPrivacyDialog(BuildContext context,
      {required Widget childWidget}) {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return childWidget;
        });
  }

  static void showView(
      BuildContext context, {
        String title = '联系客服',
        String content = '反馈邮箱：chenzhiliang@aishi.ai\n工作时间：9:00-18:00',
        Function? leftAction,
        Function? rightAction,
        bool isShowCancelBtn = false,
      }) {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return showCommonDialog(
              childWidget: CustomDialog(
                title: title,
                content: content,
                ensureAction: rightAction,
                cancelAction: leftAction,
                isShowCancelBtn: isShowCancelBtn,
              ));
        });
  }

  static showAlertView(BuildContext context) {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return showCommonDialog(
              childWidget: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Text(
                    '您还不是红娘，请申请红娘后解除此功能',
                    style:
                    TextStyle(fontSize: 16, color: ThemeColor.black3D3D3DColor),
                  ),
                  const SizedBox(
                    height: 10,
                  ),
                  Container(
                    height: 0.5,
                    color: ThemeColor.lineColor,
                  ),
                  const SizedBox(
                    height: 13,
                  ),
                  GestureDetector(
                    onTap: () {
                      Navigator.pop(context);
                    },
                    child: Text(
                      '我知道了',
                      style: TextStyle(fontSize: 16, color: ThemeColor.appColor),
                    ),
                  )
                ],
              ));
        });
  }
}

class CustomDialog extends StatelessWidget {
  final String title;
  final String content;

  final Function? ensureAction;
  final Function? cancelAction;
  final bool isShowCancelBtn;

  const CustomDialog(
      {super.key,
        this.title = '温馨提示',
        this.content = '确定要删除吗',
        this.ensureAction,
        this.cancelAction,
        this.isShowCancelBtn = false});

  @override
  Widget build(BuildContext context) {
    return contentBox(context);
  }

  contentBox(context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: <Widget>[
        Text(
          title,
          style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
        ),
        const SizedBox(
          height: 15,
        ),
        Text(
          content,
          style: const TextStyle(fontSize: 14),
        ),
        const SizedBox(
          height: 22,
        ),
        isShowCancelBtn
            ? Row(
          children: [
            const SizedBox(
              width: 20,
            ),
            getBottomBtnView(
                name: '取消',
                sendAction: cancelAction,
                borderColor: ThemeColor.checkNormalColor),
            Expanded(child: Container()),
            getBottomBtnView(
                name: '确定',
                sendAction: ensureAction,
                titleColor: ThemeColor.appColor),
            const SizedBox(
              width: 20,
            ),
          ],
        )
            : GestureDetector(
          onTap: () {
            if (ensureAction != null) {
              ensureAction!();
            }
          },
          child: Container(
            width: 70,
            height: 30,
            decoration: BoxDecoration(
                color: ThemeColor.appColor,
                borderRadius: BorderRadius.circular(15)),
            alignment: Alignment.center,
            child: const Text(
              '知道了',
              style: TextStyle(fontSize: 14, color: Colors.white),
            ),
          ),
        ),
      ],
    );
  }

  Widget getBottomBtnView({
    String name = '',
    Color? bgColor,
    Color? borderColor,
    Color? titleColor,
    Function? sendAction,
  }) {
    return GestureDetector(
      onTap: () {
        if (sendAction != null) {
          sendAction();
        }
        Get.back();
      },
      child: Container(
        width: 60,
        height: 25,
        alignment: Alignment.center,
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(20 / 2.0),
            color: bgColor,
            border: Border.all(
                color: borderColor ?? ThemeColor.appColor, width: 1)),
        child: Text(
          name,
          style: TextStyle(fontSize: 13, color: titleColor),
        ),
      ),
    );
  }
}
